<?php

include_once 'getAccessToken.php';
include_once 'baseInformatica.php';
 
if (isset($_GET['mm'])) {
    if ($_GET['mm'] != INTERIOR_SECRET) {
        exit();
    }
} else {
    exit();
}

$json = '{
    "button": [
        {
            "name": "编程杂谈",
            "sub_button": [
                {
                    "type": "view",
                    "name": "语言介绍",
                    "url": "http://wechat.everyweek.top/"
                },
                {
                    "type": "view",
                    "name": "趣味故事",
                    "url": "http://mp.weixin.qq.com/s?__biz=MzUzMzE2NTUzMQ==&mid=100000017&idx=1&sn=24fde99cbf5f1ef4eada737bc351272f&chksm=7aa965a54ddeecb3fc282b1500facbfcf5172a9c376461ab2d5d041b2abcfc3d876ee4d8edab&mpshare=1&scene=23&srcid=1106fgPCCgXoQ4kjfzNvaE00#rd"
                },
                {
                    "type": "view",
                    "name": "算法科普",
                    "url": "http://mp.weixin.qq.com/s?__biz=MzUzMzE2NTUzMQ==&mid=100000040&idx=1&sn=4e8b971f3131686de6854a79c1bd1ece&chksm=7aa9659c4ddeec8a0938375adbf6b97868c232d0628170afb6f6ffa89b23f5b6cb548b6bfc9a&mpshare=1&scene=23&srcid=11064mbkez3ZAtC0O0MKS6du#rd"
                },
                {
                    "type": "view",
                    "name": "蓝桥杯",
                    "url": "http://mp.weixin.qq.com/s?__biz=MzUzMzE2NTUzMQ==&mid=100000059&idx=1&sn=3d141f808446db8e904923a85b647b7d&chksm=7aa9658f4ddeec995f23027e043bb5342cee3fabbc80fbc9cf986012d5b38d57c671100b715a&mpshare=1&scene=23&srcid=1106ok2ehgG5Xn1p0oqQpP6T#rd"
                },
                {
                    "type": "view",
                    "name": "ACM",
                    "url": "http://mp.weixin.qq.com/s?__biz=MzUzMzE2NTUzMQ==&mid=100000054&idx=1&sn=79efaba878802b0c900e3564d9490256&chksm=7aa965824ddeec9422b0aa2d3390f2f65a0ec57a80ef6071b75fd0738c1881b999deee8128ec&mpshare=1&scene=23&srcid=1106GuoCz7iBnbVynLzWw0DU#rd\""
                }
            ]
        },
        {
            "name": "资源共享",
            "sub_button": [
                {
                    "type": "view",
                    "name": "CSDN社区",
                    "url": "https://www.csdn.net/"
                },
                {
                    "type": "view",
                    "name": "程序员的梦工厂",
                    "url": "http://www.imooc.com/"
                },
                {
                    "type": "view",
                    "name": "代码大比拼",
                    "url": "http://www.codevs.cn/info/"
                },
                {
                    "type": "view",
                    "name": "课件共享",
                    "url": "http://wechat.everyweek.top"
                }
            ]
        },
        {
            "name": "论坛交流",
            "sub_button": [
                {
                    "type": "view",
                    "name": "联系我们",
                    "url": "http://wechat.everyweek.top/"
                },
                {
                    "type": "view",
                    "name": "论坛",
                    "url": "http://wechat.everyweek.top/"
                },
                {
                    "type": "view",
                    "name": "投票",
                    "url": "http://wechat.everyweek.top/"
                }
            ]
        }
    ]
}';

$token = GetAccessToken();
$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=$token";
var_dump(create($json, $url));

function create($data, $url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $out = curl_exec($ch);
    curl_close($ch);
    return $out;
}
